package com.kevin.ymqquan.adapter;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.kevin.ymqquan.R;
import com.kevin.ymqquan.bean.ClubListData;
import com.kevin.ymqquan.bean.CoachCourseList;
import com.kevin.ymqquan.cache.ImageLoader;
import com.kevin.ymqquan.fragment.ClubFragment;

public class CourseListAdapter extends BaseAdapter {

	private List<CoachCourseList> clubList;
	private LayoutInflater lf;
	private ImageLoader mImageLoader;

	public CourseListAdapter(Activity mContext, List<CoachCourseList> clubList) {
		// TODO Auto-generated constructor stub
		this.clubList = clubList;
		mImageLoader = new ImageLoader(mContext);
		this.lf = (LayoutInflater) mContext
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	public ImageLoader getImageLoader() {
		return mImageLoader;
	}

	@Override
	public int getCount() {
		return clubList.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ClubHolder holder = null;
		holder = new ClubHolder();

		// 自定义视图
		if (convertView == null) {

			convertView = lf.inflate(R.layout.list_coach_course_item, parent,
					false);
			holder.tv_coach_course_item_coursename = (TextView) convertView
					.findViewById(R.id.tv_coach_course_item_coursename);
			holder.tv_coach_course_item_type = (TextView) convertView
					.findViewById(R.id.tv_coach_course_item_type);
			holder.tv_coach_course_item_time = (TextView) convertView
					.findViewById(R.id.tv_coach_course_item_time);
//			holder.tv_coach_course_item_price = (TextView) convertView
//					.findViewById(R.id.tv_coach_course_item_price);
			holder.tv_coach_course_item_rs = (TextView) convertView
					.findViewById(R.id.tv_coach_course_item_rs);
			holder.iv_logo_item_logo = (ImageView) convertView
					.findViewById(R.id.iv_logo_item_logo);

			convertView.setTag(holder);
		} else {
			holder = (ClubHolder) convertView.getTag();
		}

		holder.tv_coach_course_item_coursename.setText(clubList.get(position)
				.getCourseName());
		holder.tv_coach_course_item_type.setText("课程类型:"+clubList.get(position)
				.getType());
		holder.tv_coach_course_item_time.setText("课程时间:"+clubList.get(position)
				.getTime());
//		holder.tv_coach_course_item_price.setText(clubList.get(position)
//				.getPrice());
		holder.tv_coach_course_item_rs.setText("教练:"+clubList.get(position).getCoachName());

		mImageLoader.DisplayImage(clubList.get(position).getCourseLogoUrl(),
				holder.iv_logo_item_logo, false);
		return convertView;
	}

	/**
	 * 自定义控件集合
	 */
	public static class ClubHolder {
		// 名称
		public TextView tv_coach_course_item_coursename;
		// 课程类型
		public TextView tv_coach_course_item_type;
		// 课程时间
		public TextView tv_coach_course_item_time;
		// 课程价格
//		public TextView tv_coach_course_item_price;
		// 人数
		public TextView tv_coach_course_item_rs;
		// logo
		public ImageView iv_logo_item_logo;
	}

}
